package com.xiaoqiang.crm.dubbo;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.utils.StringUtils;
import com.xiaoqiang.crm.api.RemoteCompanyService;
import com.xiaoqiang.crm.api.bo.CompanyBo;
import com.xiaoqiang.crm.api.vo.CompanyVo;
import com.xiaoqiang.crm.domain.Company;
import com.xiaoqiang.crm.mapper.RemoteCompanyMapper;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
@Service
@DubboService
public class RemoteCompanyServiceImpl implements RemoteCompanyService {

    private final RemoteCompanyMapper remoteCompanyMapper;

    @Override
    public List<CompanyVo> queryList(CompanyBo bo) {
        LambdaQueryWrapper<Company> lqw = buildQueryWrapper(bo);
        return remoteCompanyMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<Company> buildQueryWrapper(CompanyBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<Company> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(bo.getName()), Company::getName, bo.getName());
        lqw.eq(StringUtils.isNotBlank(bo.getTel()), Company::getTel, bo.getTel());
        return lqw;
    }

}
